package com.ygnn;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * ClassName:test
 * Package:com.ygnn
 * Description:
 *
 * @Author: dlh
 * @Creat:2024/10/16-9:11
 */
public class test {
    public static void main(String[] args) {
        System.out.println(weekDay("2024-10-16"));
        System.out.println(weekDay("2024-10-17"));
        System.out.println(weekDay("2024-10-18"));
        System.out.println(weekDay("2024-10-19"));
        System.out.println(weekDay("2024-10-20"));
        System.out.println(weekDay("2024-10-21"));
        System.out.println(weekDay("2024-10-22"));

    }
    public static int weekDay(String time) {
        // 定义日期格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        // 将字符串转换为LocalDate对象
        LocalDate date = LocalDate.parse(time, formatter);
        // 获取星期几
        DayOfWeek dayOfWeek = date.getDayOfWeek();
        // 将星期几转换为数字
        return dayOfWeek.getValue(); // 星期一到星期天分别为1到7
    }
}
